/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import java.util.ArrayList;
import java.util.List;
import Models.PostMortem;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author HUY
 */
public class ManagingPosMortemDAO {
     public List<PostMortem> loadAllPostMortem ()
    {
        List<PostMortem> list = new ArrayList<PostMortem>();
        Connection con = DBUtility.openConnection();
        PreparedStatement stm = null ;
        ResultSet rs = null ;
        try {
            stm = con.prepareCall("select * from PostMortem");
            rs = stm.executeQuery();
            while (rs.next()) {                
                PostMortem postMortem = new PostMortem();
                postMortem.setDoctorName(rs.getString("MortalityName"));
                postMortem.setMortalityTime(rs.getDate("MortalityTime"));
                
                postMortem.setCaseID(rs.getInt("CaseID"));
                postMortem.setCheckInDate(rs.getDate("CheckInDate"));
                postMortem.setCauseOfDeath(rs.getString("CaseType"));
                postMortem.setDoctorName(rs.getString("DoctorName"));
              
                list.add(postMortem);
                        
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(CaseHistoryDAO.class.getName()).log(Level.SEVERE, null, ex);
        }finally
        {
            
            DBUtility.closeResultSet(rs);
            DBUtility.closeStatement(stm);
            DBUtility.closeConnection(con);
        }
        return list ;
    }
     
//     public boolean addNewCases(PostMortem postMortem)
//    {
//        //SimpleDateFormat df = new SimpleDateFormat("dd/mm/yy");
//        boolean result = false ;
//        Connection con = DBUtility.openConnection();
//        PreparedStatement stm = null;
//        ResultSet rs = null;
//        try {
//            stm = con.prepareStatement("insert PostMortem(MortalityName,MortalityTime,CaseID,CheckInDate,CauseOfDeath,DoctorName) values  (?,?,?,?,?,?)");
//            stm.setString(1, postMortem.getDoctorName().trim());
//            java.sql.Date _sqlMortalityTime = new java.sql.Date(postMortem.getMortalityTime().getTime());
//            stm.setDate(2, _sqlMortalityTime);
//            java.sql.Date _sqlReportedTime = new java.sql.Date(postMortem.getReportedTime().getTime());
//            stm.setDate(3, _sqlReportedTime);
//            java.sql.Date _sqlApprovalDate = new java.sql.Date(cases.getApprovalDate().getTime());
//            stm.setDate(4,_sqlApprovalDate );
//            stm.setString(5, cases.getCasePlace());            
//            stm.setString(6, cases.getCaseDescriptions());
//            stm.setString(7, cases.getCaseInvolvements());
//            stm.setInt(8, cases.getCaseStatus());
//            stm.setBoolean(9, cases.isProsecutionDesire());
//            stm.setInt(10, cases.getLeadOfficerID());
//            stm.setInt(11, cases.getApprovalDirectorID());
//            if (stm.executeUpdate() > 0) {
//                result = true;
//            }
//        } catch (SQLException ex) {
//            ex.printStackTrace();
//        }finally{
//            DBUtility.closeResultSet(rs);
//            DBUtility.closeStatement(stm);
//            DBUtility.closeConnection(con);
//        }
//        
//        return false ;
//    }
}
